# Maintainer: Saul Ibarra Corretge <saghul@gmail.com>

_realname=pyqt5
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
           "${MINGW_PACKAGE_PREFIX}-${_realname}-common")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
          "${MINGW_PACKAGE_PREFIX}-${_realname}-common")
pkgver=5.15.2
pkgrel=2
pkgdesc="Qt5 bindings for Python (mingw-w64)"
arch=('any')
license=('GPL')
url="https://riverbankcomputing.com/software/pyqt"
depends=(#"${MINGW_PACKAGE_PREFIX}-python-dbus"
         "${MINGW_PACKAGE_PREFIX}-python-pyopengl"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-pyqt5-sip"
         "${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-qtwebkit")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-sip5>=5.5.0"
             "${MINGW_PACKAGE_PREFIX}-pyqt-builder>=1.7.0")
options=('strip' 'staticlibs')
source=(https://pypi.python.org/packages/source/P/PyQt5/PyQt5-${pkgver}.tar.gz)
sha256sums=('372b08dc9321d1201e4690182697c5e7ffb2e0770e6b4a45519025134b12e4fc')

prepare() {
 cd "${srcdir}"/PyQt5-${pkgver}

}

build() {
  [[ -d python-${MINGW_CHOST} ]] && rm -rf python-${MINGW_CHOST}
  cp -r PyQt5-${pkgver} python-${MINGW_CHOST} && cd python-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--api-dir=;" \
  ${MINGW_PREFIX}/bin/sip-build \
    --confirm-license \
    --no-make \
    --api-dir=${MINGW_PREFIX}/share/qt5/qsci/api/python \
    --qmake=${MINGW_PREFIX}/bin/qmake.exe \
    --verbose

    cd build
    make V=1
}

package(){
  local _pysite=$(cygpath -u $(${MINGW_PREFIX}/bin/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"))
  cd python-${MINGW_CHOST}/build
  # INSTALL_ROOT is needed for the QtDesigner module, the other Makefiles use DESTDIR
  MSYS2_ARG_CONV_EXCL="${_pysite}" \
  make DESTDIR="${pkgdir}" INSTALL_ROOT="${pkgdir}" install

  # compile Python bytecode
  ${MINGW_PREFIX}/bin/python -m compileall -d / "$pkgdir"${MINGW_PREFIX}/lib
  ${MINGW_PREFIX}/bin/python -O -m compileall -d / "$pkgdir"${MINGW_PREFIX}/lib
}
